﻿
Partial Class store_UCTranscript
    Inherits System.Web.UI.UserControl

    Public Sub Display(p As CProduct, list As CProductList, Optional isChinese As Boolean = False)
        If Me.Parent.Controls.Count Mod 2 = 1 Then row.Attributes.Add("class", "alt_row")

        With lnkSermon
            'If p.IsSet Then .Text = p.ProductNameAndContents.Replace("1 Manual, ", "") 'Wipes out the image
            .ToolTip = String.Concat("View the Transcript(s)", vbCrLf, vbCrLf, p.ProductNameAndContents, vbCrLf, vbCrLf, CUtilities.Truncate(p.ProductDescriptionOrParent, 500))

            litTitle.Text = CUtilities.Truncate(p.ProductName, 45)

            If p.HasTranscript Then
                .NavigateUrl = CSitemap.TranscriptWithPaging(p)
            ElseIf p.Children.HavingTranscripts.Count > 0 Then
                .NavigateUrl = CSitemap.TranscriptWithPaging(p)
            Else
                .NavigateUrl = lnkSermon.NavigateUrl 'businessmens
            End If

            If isChinese Then
                colSpeaker.Visible = False

                litTitle.Text = p.ProductNameChineseSimplified

                If p.HasTranscriptChineseTrad Then
                    lnkTrad.Visible = True
                    lnkTrad.Text = p.ProductNameChineseTraditional
                    lnkTrad.NavigateUrl = CSitemap.TranscriptChineseTraditional(p)
                End If
            End If
        End With



        With lnkKindle
            If String.IsNullOrEmpty(p.ProductAmazonIdOrParent) Then
                .Visible = False
            Else
                .NavigateUrl = CSitemap.External_Amazon(p.ProductAmazonIdOrParent)
                .Text = CUtilities.Truncate(p.ProductAmazonIdOrParent, 10)
            End If
        End With

        With lnkSpeaker
            .Text = p.SpeakerName
            .NavigateUrl = CSitemap.Transcripts(Nothing, p.ProductSpeakerId)
        End With

        With lnkMobi
            If p.Files.HasMobi Then
                .Text = CUtilities.FileSize(p.Files.FirstMobi.FileSize)
                .NavigateUrl = CConfig.DropboxUrl(p.Files.FirstMobi.FileName)
            ElseIf p.HasParent AndAlso p.BelongsTo.Files.HasMobi Then
                .Text = CUtilities.FileSize(p.BelongsTo.Files.FirstMobi.FileSize)
                .NavigateUrl = CConfig.DropboxUrl(p.BelongsTo.Files.FirstMobi.FileName)
            Else
                .Visible = False
            End If
        End With

        With lnkEpub
            If p.Files.HasEpub Then
                .Text = CUtilities.FileSize(p.Files.FirstEpub.FileSize)
                .NavigateUrl = CConfig.DropboxUrl(p.Files.FirstEpub.FileName)
            ElseIf p.HasParent AndAlso p.BelongsTo.Files.HasEpub Then
                .Text = CUtilities.FileSize(p.BelongsTo.Files.FirstEpub.FileSize)
                .NavigateUrl = CConfig.DropboxUrl(p.BelongsTo.Files.FirstEpub.FileName)
            Else
                .Visible = False
            End If
        End With

        With lnkHtml
            If p.HasTranscript OrElse p.Children.HavingTranscripts.Count > 0 Then
                .NavigateUrl = CConfig.WebsiteUrl_TranscriptAsHtm(p.ProductId)
                'ElseIf p.Files.HasHtm Then
                '    .NavigateUrl = CConfig.DropboxUrl(p.Files.FirstHtm.FileName)
            Else
                .Visible = False
            End If
        End With

        With lnkDate
            lnkDate.Text = p.ProductCreated.ToString("d-MMM-yy")
            lnkDate.ToolTip = p.DateString()
            .NavigateUrl = CSitemap.Decide(p)
        End With
    End Sub
End Class
